/**
 * Copyright &copy; 2012-2014 <a href="https://github.com/thinkgem/jeesite">JeeSite</a> All rights reserved.
 */
package com.cd.cms.modules.mid.web;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.ModelAttribute;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.servlet.mvc.support.RedirectAttributes;

import com.cd.cms.common.config.Global;
import com.cd.cms.common.persistence.Page;
import com.cd.cms.common.web.BaseController;
import com.cd.cms.common.utils.StringUtils;
import com.cd.cms.modules.mid.entity.PlatformInfo;
import com.cd.cms.modules.mid.service.PlatformInfoService;

/**
 * 价格Controller
 * @author zql
 * @version 2016-05-11
 */
@Controller
@RequestMapping(value = "${adminPath}/mid/platformInfo")
public class PlatformInfoController extends BaseController {

	@Autowired
	private PlatformInfoService platformInfoService;
	
	@ModelAttribute
	public PlatformInfo get(@RequestParam(required=false) String id) {
		PlatformInfo entity = null;
		if (StringUtils.isNotBlank(id)){
			entity = platformInfoService.get(id);
		}
		if (entity == null){
			entity = new PlatformInfo();
		}
		return entity;
	}
	
	@RequiresPermissions("mid:platformInfo:view")
	@RequestMapping(value = {"list", ""})
	public String list(PlatformInfo platformInfo, HttpServletRequest request, HttpServletResponse response, Model model) {
		Page<PlatformInfo> page = platformInfoService.findPage(new Page<PlatformInfo>(request, response), platformInfo); 
		model.addAttribute("page", page);
		return "modules/mid/platformInfoList";
	}

	@RequiresPermissions("mid:platformInfo:view")
	@RequestMapping(value = "form")
	public String form(PlatformInfo platformInfo, Model model) {
		model.addAttribute("platformInfo", platformInfo);
		return "modules/mid/platformInfoForm";
	}

	@RequiresPermissions("mid:platformInfo:edit")
	@RequestMapping(value = "save")
	public String save(PlatformInfo platformInfo, Model model, RedirectAttributes redirectAttributes) {
		if (!beanValidator(model, platformInfo)){
			return form(platformInfo, model);
		}
		platformInfoService.save(platformInfo);
		addMessage(redirectAttributes, "保存价格成功");
		return "redirect:"+Global.getAdminPath()+"/mid/platformInfo/?repage";
	}
	
	@RequiresPermissions("mid:platformInfo:edit")
	@RequestMapping(value = "delete")
	public String delete(PlatformInfo platformInfo, RedirectAttributes redirectAttributes) {
		platformInfoService.delete(platformInfo);
		addMessage(redirectAttributes, "删除价格成功");
		return "redirect:"+Global.getAdminPath()+"/mid/platformInfo/?repage";
	}

}